//文件上传模块
const express = require('express');
const multer = require("multer");
const pool = require('../pool.js')
const file_upload = express.Router();
const storage = multer.diskStorage({
    destination(req, file, cb) {
        cb(null, "public/images");
    },
    filename(req, file, cb) {
        let file_name = Date.now() + '_' + file.originalname;
        cb(null, file_name);
    }
})

const imgUpload = multer({ storage });
//文件上传接口
file_upload.post('/file_upload', imgUpload.single("file"), (req, res) => {
    if (req.file.filename) {
        res.send({ code: 1, message: '图片上传成功！', data: req.file.filename })
    } else {
        res.send({ code: 0, message: '图片上传失败！' })
    }
})


module.exports = file_upload;